//
//  Inode.h
//  LearningOops
//
//  Created by Swetha Patnala on 4/14/13.
//  Copyright (c) 2013 Swetha Patnala. All rights reserved.
//

#ifndef __LearningOops__Inode__
#define __LearningOops__Inode__

#include <iostream>
#include <string.h>
#include <vector>

#define NUM_OF_FILE_DESCRIPTORS 32
using namespace std;


typedef struct {
    int fd_number ;
    int fd_start;
    int fd_current;
}file_descriptor_table;


typedef struct {
    
    int inode_number;
    char* file_name;
    char* mode ; //can this file be read/written/executed
    int size_of_file;
    int number_of_blocks_allocated_to_file;
    vector <int> inode_vector;
    time_t  time_of_creation;
    time_t  last_access_time;
    time_t  last_modification_time;
    int userid;
    int groupid;
    
    
    file_descriptor_table* fd[NUM_OF_FILE_DESCRIPTORS+1];
    
}inode_structure ;

class Inode{
    
    
public:
    
    inode_structure* inode ;
    int file_descriptor_count = 0;
    
    
    
    Inode();
    Inode(int num , char* name);
    char* getName();
    int getNum();
    int getSizeOfFile();
    
    void printInode();
    int tell_file_system_manager();
    int increment_file_descriptor();
    int decrement_file_descriptor();
    bool isFileDescriptorFull();
    int getFreeFileDescriptor();
    int getFileDescriptorCount();
    int allocateFileDescriptor(int fd_num);
    int deallocateFileDescriptor(int num);
    int set_Data_Block_num(int data_block_num);
    int get_Data_Block_num();
    void addToInodeVector(int datablock_num);
    void printInodeVector();
    vector <int> getInodeVector();
    inode_structure* get_inode_structure();
    bool isFileDescriptorAvailable(int fd);
    time_t getCurrentTime();
    void set_createTime(time_t t);
    void set_ModifiedTime(time_t t);
    void set_LastAccessTime(time_t t);
    void displayTime(time_t t);
    void increment_num_of_datablocks();
};


#endif /* defined(__LearningOops__Inode__) */
